package com.jingyanzi.member.service.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jingyanzi.marketing.domain.GiveDo;
import com.jingyanzi.marketing.factory.MarketingFactory;
import com.jingyanzi.marketing.service.IGiveService;
import com.jingyanzi.member.dao.MAccountFinanceMapper;
import com.jingyanzi.member.dao.MAccountMapper;
import com.jingyanzi.member.dao.MAccountPayMapper;
import com.jingyanzi.member.dao.MAccountRechargeMapper;
import com.jingyanzi.member.domain.AccountDO;
import com.jingyanzi.member.domain.AccountFinanceDO;
import com.jingyanzi.member.domain.AccountPayDO;
import com.jingyanzi.member.domain.AccountRechargeDO;
import com.jingyanzi.member.domain.CustomerDO;
import com.jingyanzi.member.domain.CustomerFamilyDO;
import com.jingyanzi.member.domain.MemberDO;
import com.jingyanzi.member.domain.result.ResultDO;
import com.jingyanzi.member.domain.result.ResultSupport;
import com.jingyanzi.member.entity.MAccount;
import com.jingyanzi.member.entity.MAccountExample;
import com.jingyanzi.member.entity.MAccountFinance;
import com.jingyanzi.member.entity.MAccountFinanceExample;
import com.jingyanzi.member.entity.MAccountPay;
import com.jingyanzi.member.entity.MAccountPayExample;
import com.jingyanzi.member.entity.MAccountPayExample.Criteria;
import com.jingyanzi.member.entity.MAccountRecharge;
import com.jingyanzi.member.entity.MAccountRechargeExample;
import com.jingyanzi.member.query.AccountFinanceQueryDO;
import com.jingyanzi.member.query.AccountPayQueryDO;
import com.jingyanzi.member.query.AccountQueryDO;
import com.jingyanzi.member.query.AccountRechargeQueryDO;
import com.jingyanzi.member.query.CustomerFamilyQueryDO;
import com.jingyanzi.member.service.IAccountService;
import com.jingyanzi.member.service.ICustomerService;
import com.jingyanzi.member.service.ICustomerFamilyService;
import com.jingyanzi.member.service.IMemberService;
import com.jingyanzi.member.util.BeanUtilsExtends;
import com.jingyanzi.member.util.MemberConstant;
import com.jingyanzi.member.util.StaticDicUtil;
import com.jingyanzi.privilege.domain.EmployeeDO;
import com.jingyanzi.resallocation.domain.StoreDO;
import com.jingyanzi.resallocation.factory.ResFactory;
import com.jingyanzi.resallocation.service.IStoreService;

@Service("accountService")
public class AccountServiceImpl extends BaseServiceImpl implements IAccountService {

	private static Logger logger = Logger.getLogger(AccountServiceImpl.class);

	@Autowired
	private MAccountMapper accountMapper;

	@Autowired
	private MAccountPayMapper accountPayMapper;

	@Autowired
	private MAccountRechargeMapper accountRechargeMapper;

	@Autowired
	private MAccountFinanceMapper accountFinanceMapper;

	@Autowired
	private ICustomerService customerService;

	@Autowired
	private ICustomerFamilyService customerFamilyService;

	@Autowired
	private IMemberService memberService;
	
	/*@Autowired
	private ICustomerSolrService solrService;*/

	
	private IGiveService getGiveService() {
		return MarketingFactory.getGiveService();
	}

	private IStoreService getStoreService() {
		return ResFactory.getStoreService();
	}

	public ResultDO add(AccountDO domain) {

		MAccount entity = new MAccount();
		ResultSupport result = new ResultSupport();
		// 参数判断
		if (domain == null || isNumberInValid(domain.getId())) {
			result.setSuccess(false);
			result.setErrorCode(ResultDO.PARAM_ERROR);
			result.setErrorMsg("参数错误");
			logger.error("参数错误：账户DO对象为空");
			return result;
		}

		result = BeanUtilsExtends.copy(entity, domain);
		if (!result.isSuccess()) {
			result.setErrorCode(ResultDO.ACCOUNT_ADD_ERROR);
			result.setErrorMsg("账户信息转换失败");
			result.setSuccess(false);
			logger.error("客户账户对象转换失败");
			return result;
		}

		entity.setCreatetime(Calendar.getInstance().getTime());
		entity.setModifitime(entity.getCreatetime());
		// 所有账户资金信息初始化为0
		entity.setBalance(new BigDecimal(0.00)); // 余额
		entity.setDeposit(new BigDecimal(0.00)); // 最近充值金额
		entity.setPayment(new BigDecimal(0.00)); // 最近消费金额
		entity.setTotle(new BigDecimal(0.00)); // 累计消费金额
		entity.setCount(0); // 消费次数
		entity.setOrderNum(0); // 订单数
		entity.setIsDelete(MemberConstant.DB_ISDEL_NO);
		int r = -1;
		try {
			r = accountMapper.insert(entity);
		} catch (Exception e) {
			e.printStackTrace();
			result.setErrorCode(ResultDO.ACCOUNT_ADD_ERROR);
			result.setErrorMsg("客户账户创建失败");
			result.setSuccess(false);
			logger.error("客户账户创建异常 ");
			return result;
		}
		if (r < 1) {
			result.setErrorCode(ResultDO.ACCOUNT_ADD_ERROR);
			result.setErrorMsg("客户账户创建失败");
			result.setSuccess(false);
			logger.error("客户账户创建失败 ");
			return result;
		}
		result.setModel(ResultDO.FIRST_MODEL_KEY, entity.getId());
		return result;
	}

	public ResultDO remove(Integer id) {

		ResultSupport result = new ResultSupport();
		// 参数判断
		if (isNumberInValid(id)) {
			result.setSuccess(false);
			result.setErrorCode(ResultDO.PARAM_ERROR);
			result.setErrorMsg("参数错误");
			logger.error("客户账户id为空");
			return result;
		}
		MAccount entity = new MAccount();

		entity.setId(id);
		entity.setIsDelete(MemberConstant.DB_ISDEL_YES);

		int r = -1;

		try {
			r = accountMapper.updateByPrimaryKeySelective(entity);
		} catch (Exception e) {
			e.printStackTrace();
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("账户删除失败");
			result.setSuccess(false);
			logger.error("客户账户删除失败 id=" + id);
			return result;
		}

		if (r < 1) {
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("账户删除失败");
			result.setSuccess(false);
			logger.error("客户账户删除失败 id=" + id);
			return result;
		}

		return result;
	}

	public ResultDO modifi(AccountDO domain) {

		MAccount entity = new MAccount();
		ResultSupport result = new ResultSupport();
		// 参数判断
		if (domain == null || isNumberInValid(domain.getId())) {
			result.setSuccess(false);
			result.setErrorCode(ResultDO.PARAM_ERROR);
			result.setErrorMsg("参数错误");
			logger.error("账户DO对象为空或id无效");
			return result;
		}
		result = BeanUtilsExtends.copy(entity, domain);
		if (!result.isSuccess())
			return result;

		entity.setModifitime(Calendar.getInstance().getTime());

		int r = -1;
		try {
			r = accountMapper.updateByPrimaryKeySelective(entity);
		} catch (Exception e) {
			e.printStackTrace();
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("客户账户修改失败");
			result.setSuccess(false);
			logger.error("客户账户修改失败 id=" + domain.getId());
			return result;
		}
		if (r < 1) {
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("账户修改失败");
			result.setSuccess(false);
			logger.error("客户账户修改失败 id=" + domain.getId());
			return result;
		}

		return result;
	}

	public ResultDO get(Integer id) {

		ResultSupport result = new ResultSupport();
		// 参数判断
		if (isNumberInValid(id)) {
			result.setErrorCode(ResultDO.PARAM_ERROR);
			result.setErrorMsg("参数错误");
			result.setSuccess(false);
			logger.error("客户id无效");
			return result;
		}

		MAccount entity = null;

		try {
			entity = accountMapper.selectByPrimaryKey(id);
		} catch (Exception e) {
			e.printStackTrace();
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("账户获取失败");
			result.setSuccess(false);
			logger.error("客户账户查询失败 id=" + id);
			return result;
		}

		result.setModel(ResultSupport.FIRST_MODEL_KEY, getAccountDO(entity));
		return result;
	}

	/** 提交账户充值订单，返回充值订单id */
	@Override
	public ResultDO recharge(AccountRechargeDO accountRechargeDO) {
		ResultSupport result = new ResultSupport();
		// 判断参数
		if (accountRechargeDO == null || isNumberInValid(accountRechargeDO.getAccountId())) {
			result.setErrorCode(ResultDO.PARAM_ERROR);
			result.setErrorMsg("参数错误");
			result.setSuccess(false);
			logger.error("账户充值DO对象为空或id无效");
			return result;
		}

		MAccountRecharge entity = new MAccountRecharge();
		result = BeanUtilsExtends.copy(entity, accountRechargeDO);
		if (!result.isSuccess()) {
			logger.error("账户充值信息转换失败");
			return result;
		}

		entity.setIsDelete(MemberConstant.DB_ISDEL_NO);
		entity.setStatus(MemberConstant.STATUS_ORDER); // 提交支付订单
		entity.setCreatetime(Calendar.getInstance().getTime());
		// 获得有效的账户信息
		MAccount mAccount = accountMapper.selectByPrimaryKey(entity.getAccountId());
		if (mAccount == null) {
			result.setErrorCode(ResultDO.ACCOUNT_RECHARGE_ERROR);
			result.setErrorMsg("不存在该会员账户");
			result.setSuccess(false);
			logger.error("不存在该账户 id=" + entity.getAccountId());
			return result;
		}
		if (!isNumberInValid(entity.getStoreId())) {
			// 获得门店信息
			StoreDO storeDO = getStroreById(entity.getStoreId());
			if (null == storeDO) {
				result.setErrorCode(ResultDO.ACCOUNT_RECHARGE_ERROR);
				result.setErrorMsg("不存在该门店信息");
				result.setSuccess(false);
				logger.error("不存在该门店账户 id=" + entity.getStoreId());
				return result;
			}
			entity.setStoreName(storeDO.getName());
		}
		CustomerFamilyQueryDO query = new CustomerFamilyQueryDO();
		query.setCustomerId(entity.getAccountId());
		query.setIsFirst(1);
		// 获取客户信息
		ResultDO res = customerFamilyService.query(query);
		if (!res.isSuccess()) {
			result.setErrorCode(ResultDO.MEMBER_ADD_ERROR);
			result.setErrorMsg("获取客户信息失败");
			result.setSuccess(false);
			return result;
		}

		List<CustomerFamilyDO> listFamily = (List<CustomerFamilyDO>) res.getModel(ResultSupport.FIRST_MODEL_KEY);

		CustomerFamilyDO domain2 = listFamily.get(0);
		// 客户首要联系人电话
		entity.setTelephone(domain2.getTelephone());
		// 客户首要联系人名字
		entity.setCustomerName(domain2.getName());

		if (!isNumberInValid(entity.getEmployeeId())) {
			// 得到员工信息（充值开单人员）
			EmployeeDO employeeDO = getEmployeeById(entity.getEmployeeId());
			if (employeeDO == null) {
				result.setErrorCode(ResultDO.ACCOUNT_RECHARGE_ERROR);
				result.setErrorMsg("获取员工信息失败");
				result.setSuccess(false);
				logger.error("员工信息查询失败 id=" + entity.getEmployeeId());
				return result;
			}

			// 设置开单人员姓名
			entity.setEmployeeName(employeeDO.getRealName());
		}
		// 判断是否是活动充值
		if (!isNumberInValid(entity.getActivityId())) {
			// 得到活动信息
			com.jingyanzi.marketing.result.ResultDO giveResultDO = getGiveService().get(entity.getActivityId());
			if (!giveResultDO.isSuccess()) {
				result.setErrorCode(ResultDO.ACCOUNT_RECHARGE_ERROR);
				result.setErrorMsg("充值活动信息获取失败");
				result.setSuccess(false);
				logger.error("充值活动信息获取失败 id=" + entity.getActivityId());
				return result;
			}
			GiveDo give = (GiveDo) giveResultDO.getModel(com.jingyanzi.marketing.result.ResultSupport.FIRST_MODEL_KEY);
			if (give != null) {
				// 活动名称
				entity.setActivityName(give.getActivityOption());
				// 赠送金额
				entity.setGiftAmount(give.getAmountGive());
			}
		} else {
			// 不是活动充值没有赠送金额，赠送金额设置为0
			entity.setGiftAmount(new BigDecimal(0.00));
		}
		// 先显示为充值前账户余额，收银成功后，再重新计算余额
		entity.setBalance(mAccount.getBalance());
		int r = -1;
		try {
			r = accountRechargeMapper.insert(entity);
			logger.info("客户充值 客户id:" + entity.getAccountId() + ", 充值金额：" + entity.getRechargeAmount() + "， 赠送金额："
					+ entity.getGiftAmount() + ", 状态：生成充值账单，未支付");
		} catch (Exception e) {
			e.printStackTrace();
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("充值记录添加失败");
			result.setSuccess(false);
			logger.error(ResultDO.SYSTEM_EXCEPTION_ERROR_MSG + " 充值记录添加异常");
			return result;
		}
		if (r < 1) {
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("充值记录添加失败");
			result.setSuccess(false);
			logger.error(ResultDO.SYSTEM_EXCEPTION_ERROR_MSG + " 充值记录添加失败");
			return result;
		}
		result.setModel(ResultDO.FIRST_MODEL_KEY, entity.getId());
		return result;
	}

	public ResultDO removeRecharge(Integer id) {

		ResultSupport result = new ResultSupport();
		// 参数判断
		if (isNumberInValid(id)) {
			result.setSuccess(false);
			result.setErrorCode(ResultDO.PARAM_ERROR);
			result.setErrorMsg("参数错误");
			logger.error("充值记录id为空");
			return result;
		}

		MAccountRecharge entity = new MAccountRecharge();

		entity.setId(id);
		entity.setIsDelete(MemberConstant.DB_ISDEL_YES);

		int r = -1;

		try {
			r = accountRechargeMapper.updateByPrimaryKeySelective(entity);
		} catch (Exception e) {
			e.printStackTrace();
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("账户充值订单删除失败");
			result.setSuccess(false);
			logger.error("充值记录删除失败 id:" + id);
			return result;
		}

		if (r < 1) {
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("账户充值订单删除失败");
			result.setSuccess(false);
			logger.error("充值订单删除失败 id:" + id);
			return result;
		}

		return result;
	}

	/** 新增消费记录 */
	@Override
	public ResultDO addPay(AccountPayDO accountPay) {
		ResultSupport result = new ResultSupport();
		// 判断参数
		if (accountPay == null || isNumberInValid(accountPay.getAccountId())) {
			result.setErrorCode(ResultDO.PARAM_ERROR);
			result.setErrorMsg("参数错误");
			result.setSuccess(false);
			logger.error("消费DO对象为空或客户id无效");
			return result;
		}

		MAccountPay entity = new MAccountPay();
		result = BeanUtilsExtends.copy(entity, accountPay);
		if (!result.isSuccess()) {
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("消费信息转换失败");
			result.setSuccess(false);
			logger.error("消费DO对象转换失败");
			return result;
		}
		// 如果是订单或加选，则查询订单号是否已存在，若不存在，则账户表订单数+1； 若存在，则订单数不变
		int orderNum = -1;
		if (MemberConstant.TRADE_TYPE_ORDER == entity.getTradeType()
				|| MemberConstant.TRADE_TYPE_ADD == entity.getTradeType()) {
			MAccountPayExample example = new MAccountPayExample();
			MAccountPayExample.Criteria criteria = example.createCriteria();
			if (entity.getAccountId() != null) {
				criteria.andAccountIdEqualTo(entity.getAccountId());
			}
			if (entity.getOrderNo() != null) {
				criteria.andOrderNoEqualTo(entity.getOrderNo());
			}
			criteria.andIsDeleteEqualTo(MemberConstant.DB_ISDEL_NO);
			orderNum = accountPayMapper.countByExample(example);
		}

		CustomerFamilyQueryDO query = new CustomerFamilyQueryDO();
		query.setCustomerId(entity.getAccountId());
		query.setIsFirst(1);
		// 获取客户信息
		ResultDO res = customerFamilyService.query(query);
		if (!res.isSuccess()) {
			result.setErrorCode(ResultDO.MEMBER_ADD_ERROR);
			result.setErrorMsg("获取客户信息失败");
			result.setSuccess(false);
			return result;
		}

		List<CustomerFamilyDO> listFamily = (List<CustomerFamilyDO>) res.getModel(ResultSupport.FIRST_MODEL_KEY);

		CustomerFamilyDO domain2 = listFamily.get(0);
		entity.setCustomerName(domain2.getName());
		// (2)查询门店id
		if (!isNumberInValid(entity.getStoreId())) {
			StoreDO storeDO = getStroreById(entity.getStoreId());
			if (null == storeDO) {
				logger.error(ResultDO.DB_NO_ERROR + "门店信息查询失败 门店id:" + entity.getStoreId());
			} else {
				entity.setStoreName(storeDO.getName());
			}
		}
		// (3)查询销售人员信息
		if (!isNumberInValid(entity.getSalesId())) {
			EmployeeDO employeeDO = getEmployeeById(entity.getSalesId());
			if (employeeDO == null) {
				logger.error(ResultDO.QUERY_PERSONAL_ERROR + "获取销售员工信息失败，员工id:" + entity.getSalesId());
			} else {
				entity.setSalesName(employeeDO.getRealName());
			}
		}
		// （4）查询收银人员信息
		if (!isNumberInValid(entity.getCashierId())) {
			EmployeeDO employeeDO = getEmployeeById(entity.getCashierId());
			if (employeeDO == null) {
				logger.error(ResultDO.QUERY_PERSONAL_ERROR + "获取收银人员信息失败，员工id:" + entity.getCashierId());
				return result;
			} else {
				entity.setCashierName(employeeDO.getRealName());
			}
		}
		// （5）消费金额默认为实际结算金额
		entity.setConsumeAmount(accountPay.getSettleAmount());
		entity.setCreatetime(Calendar.getInstance().getTime());
		entity.setIsDelete(MemberConstant.DB_ISDEL_NO);
		// 新增消费支出
		int r = -1;
		try {
			r = accountPayMapper.insert(entity);
			logger.info("新增客户消费记录，客户id:" + entity.getAccountId() + ",交易类型："
					+ StaticDicUtil.PAY_CASH_NAMES.get(entity.getTradeType()) + ",交易金额：" + entity.getSettleAmount());
		} catch (Exception e) {
			e.printStackTrace();
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("消费记录添加失败");
			result.setSuccess(false);
			logger.error("客户消费记录添加异常");
			return result;
		}
		if (r < 1) {
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("消费记录添加失败");
			result.setSuccess(false);
			logger.error("客户消费记录添加失败");
			return result;
		}
		result.setModel(ResultDO.FIRST_MODEL_KEY, entity.getId());

		// 2.更新账户信息表（消费金额、消费时间、消费次数、累计消费金额信息）
		// 不更新账户余额，账户余额的修改在addFinanceRecord方法中进行
		MAccount mAccount = accountMapper.selectByPrimaryKey(entity.getAccountId());
		if (null == mAccount) {
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("账户信息查询失败");
			result.setSuccess(false);
			logger.error("客户账户信息查询失败，id:" + entity.getAccountId());
		}
		// 一个订单号只计算一次订单数，若订单号已存在，则不再加1； 不存在，则订单数加1
		if (orderNum == 0) {
			mAccount.setOrderNum(mAccount.getOrderNum() + 1);
		}
		mAccount.setPayment(entity.getSettleAmount()); // 实际结算金额
		mAccount.setPayDate(Calendar.getInstance().getTime());
		mAccount.setCount(mAccount.getCount() + 1); // 消费次数:根据账单数来定，即为消费记录数
		mAccount.setTotle(mAccount.getTotle().add(entity.getSettleAmount())); // 累计消费金额
		mAccount.setModifi(entity.getAuthor());
		mAccount.setModifitime(Calendar.getInstance().getTime());
		try {
			r = accountMapper.updateByPrimaryKeySelective(mAccount);
			logger.info("修改客户累计消费数据，客户id:" + entity.getAccountId() + ",累计交易：" + mAccount.getTotle());
		} catch (Exception e) {
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("客户账户信息更新失败");
			result.setSuccess(false);
			logger.error("客户账户信息更新异常，id:" + entity.getAccountId());
			return result;
		}
		if (r < 1) {
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("客户账户信息更新失败");
			result.setSuccess(false);
			logger.error("客户账户信息更新失败，id:" + entity.getAccountId());
			return result;
		}

		// 3.如果是购买会员，则更新会员表、客户表状态
		if (entity.getTradeType() == MemberConstant.TRADE_TYPE_MEMBER) {
			// a.更新客户表isMember会员标识及status客户类型
			CustomerDO customerDO = new CustomerDO();
			customerDO.setId(domain2.getCustomerId());
			customerDO.setIsMember(MemberConstant.CUSTOMER_MEMBER);
			customerDO.setStatus(MemberConstant.CUSTOMER_TYPE_MEMBER);
			customerService.modifi(customerDO);
			// b.会员表激活会员状态
			MemberDO memberDO = new MemberDO();
			memberDO.setId(domain2.getCustomerId());
			ResultDO resultDO2 = memberService.activity(memberDO);
			if (!resultDO2.isSuccess()) {
				return resultDO2;
			}
		}

		// 更新solr
		//solrService.addRecord(entity.getAccountId());
		return result;
	}

	@Override
	public ResultDO queryPay(AccountPayQueryDO accountPayQueryDO) {

		ResultSupport result = new ResultSupport();
		// 判断参数
		if (accountPayQueryDO == null) {
			result.setErrorCode(ResultDO.PARAM_ERROR);
			result.setErrorMsg("参数错误");
			result.setSuccess(false);
			logger.error("消费查询DO对象为空");
			return result;
		}

		List<MAccountPay> list = null;

		MAccountPayExample example = new MAccountPayExample();
		Criteria createCriteria = example.createCriteria();
		// 客户id（考虑客户合并）
		if (!isNumberInValid(accountPayQueryDO.getAccountId())) {
			createCriteria.andAccountIdIn(createCustomerId(accountPayQueryDO.getAccountId()));
		}
		// 暂时未使用
		if (!StringUtils.isEmpty(accountPayQueryDO.getCustomerNo())) {
			createCriteria.andCustomerNoEqualTo(accountPayQueryDO.getCustomerNo());
		}
		// 订单号
		if (!StringUtils.isEmpty(accountPayQueryDO.getOrderNo())) {
			createCriteria.andOrderNoEqualTo(accountPayQueryDO.getOrderNo());
		}
		// 交易号
		if (!StringUtils.isEmpty(accountPayQueryDO.getTradeNo())) {
			createCriteria.andTradeNoEqualTo(accountPayQueryDO.getTradeNo());
		}
		// 客户姓名
		if (!StringUtils.isEmpty(accountPayQueryDO.getCustomerName())) {
			createCriteria.andCustomerNameEqualTo(accountPayQueryDO.getCustomerName());
		}
		// 交易类型
		if (accountPayQueryDO.getTradeType() != null) {
			createCriteria.andTradeTypeIn(Arrays.asList(accountPayQueryDO.getTradeType()));
		}
		createCriteria.andIsDeleteEqualTo(MemberConstant.DB_ISDEL_NO);

		List<AccountPayDO> payList = null;

		if (accountPayQueryDO.isPage()) {
			example.setLimitByPage(accountPayQueryDO.getStart() + "," + accountPayQueryDO.getPageRows());
			long count = accountPayMapper.countByExample(example);
			result.setModel(ResultSupport.SECOND_MODEL_KEY, count);
		}

		try {
			list = accountPayMapper.selectByExample(example);
		} catch (Exception e) {
			e.printStackTrace();
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("客户消费记录获取失败");
			result.setSuccess(false);
			logger.error("获取客户消费记录失败");
			return result;
		}

		payList = getAccountPayDOList(list);
		result.setModel(ResultSupport.FIRST_MODEL_KEY, payList);

		return result;
	}

	@Override
	public ResultDO queryFinance(AccountFinanceQueryDO accountFinanceQueryDO) {
		ResultSupport result = new ResultSupport();
		// 判断参数
		if (accountFinanceQueryDO == null) {
			result.setErrorCode(ResultDO.PARAM_ERROR);
			result.setErrorMsg("参数错误");
			result.setSuccess(false);
			logger.error("账户资金记录查询DO对象为空");
			return result;
		}

		List<MAccountFinance> list = null;
		MAccountFinanceExample example = new MAccountFinanceExample();

		com.jingyanzi.member.entity.MAccountFinanceExample.Criteria criteria = example.createCriteria();
		// 客户id（考虑客户合并）
		if (!isNumberInValid(accountFinanceQueryDO.getAccountId())) {
			criteria.andAccountIdIn(createCustomerId(accountFinanceQueryDO.getAccountId()));
		}

		criteria.andIsDeleteEqualTo(MemberConstant.DB_ISDEL_NO);

		List<AccountFinanceDO> finanList = null;

		if (accountFinanceQueryDO.isPage()) {
			example.setLimitByPage(accountFinanceQueryDO.getStart() + "," + accountFinanceQueryDO.getPageRows());
			long count = accountFinanceMapper.countByExample(example);
			result.setModel(ResultSupport.SECOND_MODEL_KEY, count);
		}
		try {
			list = accountFinanceMapper.selectByExample(example);
		} catch (Exception e) {
			e.printStackTrace();
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg(ResultDO.SYSTEM_EXCEPTION_ERROR_MSG + "获取账户资金记录失败");
			result.setSuccess(false);
			logger.error("获取账户资金记录失败");
			return result;
		}

		finanList = getAccountFinanDOList(list);
		result.setModel(ResultSupport.FIRST_MODEL_KEY, finanList);

		return result;
	}

	@Override
	public ResultDO queryAccount(AccountQueryDO accountQueryDO) {
		ResultSupport result = new ResultSupport();
		// 判断参数
		if (accountQueryDO == null) {
			result.setErrorCode(ResultDO.PARAM_ERROR);
			result.setErrorMsg("参数错误");
			result.setSuccess(false);
			logger.error("账户查询DO对象为空");
			return result;
		}

		MAccountExample example = new MAccountExample();
		com.jingyanzi.member.entity.MAccountExample.Criteria criteria = example.createCriteria();
		criteria.andIsDeleteEqualTo(MemberConstant.DB_ISDEL_NO);

		// 客户id（考虑客户合并）
		if (!StringUtils.isEmpty(accountQueryDO.getCustomerNo())) {
			criteria.andCustomerNoEqualTo(accountQueryDO.getCustomerNo());
		}

		if (accountQueryDO.isPage()) {
			example.setLimitByPage(accountQueryDO.getStart() + "," + accountQueryDO.getPageRows());
			long count = accountMapper.countByExample(example);
			result.setModel(ResultSupport.SECOND_MODEL_KEY, count);
		}

		List<MAccount> list = null;
		try {
			list = accountMapper.selectByExample(example);
		} catch (Exception e) {
			e.printStackTrace();
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("账户信息获取失败");
			result.setSuccess(false);
			logger.error("账户信息获取失败");
			return result;
		}

		List<AccountDO> accountList = getAccountDOList(list);
		result.setModel(ResultSupport.FIRST_MODEL_KEY, accountList);

		return result;
	}

	@Override
	public ResultDO queryAccountRecharge(AccountRechargeQueryDO queryDO) {
		ResultSupport result = new ResultSupport();
		// 判断参数
		if (queryDO == null) {
			result.setErrorCode(ResultDO.PARAM_ERROR);
			result.setErrorMsg("参数错误");
			result.setSuccess(false);
			logger.error("账户充值记录查询DO对象为空");
			return result;
		}

		MAccountRechargeExample example = new MAccountRechargeExample();
		com.jingyanzi.member.entity.MAccountRechargeExample.Criteria criteria = example.createCriteria();
		criteria.andIsDeleteEqualTo(MemberConstant.DB_ISDEL_NO);

		// 客户id（考虑客户合并）
		if (!isNumberInValid(queryDO.getAccountId())) {
			criteria.andAccountIdIn(createCustomerId(queryDO.getAccountId()));
		}

		if (queryDO.isPage()) {
			example.setLimitByPage(queryDO.getStart() + "," + queryDO.getPageRows());
			long count = accountRechargeMapper.countByExample(example);
			result.setModel(ResultSupport.SECOND_MODEL_KEY, count);
		}
		List<MAccountRecharge> list = null;
		try {
			list = accountRechargeMapper.selectByExample(example);
		} catch (Exception e) {
			e.printStackTrace();
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("账户充值记录获取失败");
			result.setSuccess(false);
			logger.error("账户充值记录查询失败");
			return result;
		}

		List<AccountRechargeDO> accountList = getAccountRechargeDOList(list);
		result.setModel(ResultSupport.FIRST_MODEL_KEY, accountList);

		return result;
	}

	/**
	 * 对象拷贝单个实体到对象中
	 * 
	 * @param obj
	 * @return 返回DO对象
	 */
	public AccountRechargeDO getAccountRechargeDO(MAccountRecharge obj) {
		if (obj == null)
			return null;
		AccountRechargeDO dst = new AccountRechargeDO();
		return BeanUtilsExtends.copyProperties(dst, obj) ? dst : null;
	}

	/**
	 * 对象拷贝多个实体到列表中
	 * 
	 * @param List
	 * @return List
	 */
	public List<AccountRechargeDO> getAccountRechargeDOList(List<MAccountRecharge> list) {
		List<AccountRechargeDO> result = new ArrayList<AccountRechargeDO>();
		if (list != null && !list.isEmpty()) {
			for (MAccountRecharge org : list) {
				AccountRechargeDO org1 = getAccountRechargeDO(org);
				if (org1 != null) {
					org1.setCreateTimeName(String.valueOf(org.getCreatetime().getTime()));
					// 设置总的充值金额（充值金额+赠送金额）
					org1.setRechargeAmount(org.getRechargeAmount().add(org.getGiftAmount()));
					if (org1.getStatus() == MemberConstant.STATUS_ORDER) {
						// 订单未支付
						org1.setStatusName("待支付");
					} else {
						// 订单已支付
						org1.setPayDate(String.valueOf(org.getPayDate().getTime()));
						org1.setStatusName("已支付");
					}
					// 订单编号
					org1.setOrderNo("CZ" + org1.getOrderNo());
					result.add(org1);
				}
			}
		}
		return result;
	}

	/**
	 * 对象拷贝单个实体到对象中
	 * 
	 * @param obj
	 * @return 返回DO对象
	 */
	public AccountFinanceDO getAccountFinanDO(MAccountFinance obj) {
		if (obj == null)
			return null;
		AccountFinanceDO dst = new AccountFinanceDO();
		return BeanUtilsExtends.copyProperties(dst, obj) ? dst : null;
	}

	/**
	 * 对象拷贝多个实体到列表中
	 * 
	 * @param List
	 * @return List
	 */
	public List<AccountFinanceDO> getAccountFinanDOList(List<MAccountFinance> list) {
		List<AccountFinanceDO> result = new ArrayList<AccountFinanceDO>();
		if (list != null && !list.isEmpty()) {
			for (MAccountFinance org : list) {
				AccountFinanceDO org1 = getAccountFinanDO(org);
				if (org1 != null) {
					CustomerFamilyQueryDO query = new CustomerFamilyQueryDO();
					query.setCustomerId(org.getAccountId());
					query.setIsFirst(1);
					// 获取客户信息
					ResultDO res = customerFamilyService.query(query);
					

					List<CustomerFamilyDO> listFamily = (List<CustomerFamilyDO>) res.getModel(ResultSupport.FIRST_MODEL_KEY);

					CustomerFamilyDO domain2 = listFamily.get(0);
					if (domain2 != null) {
						org1.setTelephone(domain2.getTelephone());
					}
					org1.setTradeTypeName(StaticDicUtil.PAY_CASH_NAMES.get(org1.getTradeType()));
					org1.setPayModeName(StaticDicUtil.PAY_METHOD_NAMES.get(org1.getPayMode()));
					org1.setCreateTimeName(String.valueOf(org.getCreatetime().getTime()));
					result.add(org1);
				}
			}
		}
		return result;
	}

	/**
	 * 充值订单收银成功后，调用更新充值订单相关信息（充值订单表、账户表、资金记录表）
	 */
	public ResultDO updateRecharge(AccountFinanceDO accountFinanceDO) {

		ResultSupport result = new ResultSupport();
		// 判断参数: 客户id, 充值订单交易号
		if (accountFinanceDO == null || isNumberInValid(accountFinanceDO.getAccountId())
				|| StringUtils.isEmpty(accountFinanceDO.getTradeNo())) {
			result.setErrorCode(ResultDO.PARAM_ERROR);
			result.setErrorMsg("参数错误");
			result.setSuccess(false);
			logger.error("账户充值查询DO对象为空");
			return result;
		}

		MAccountFinance finance = new MAccountFinance();
		result = BeanUtilsExtends.copy(finance, accountFinanceDO);
		if (!result.isSuccess())
			return result;

		// 根据收银台返回的信息，修改相关数据表： 账户充值表；账户表；资金记录表
		// 1.查询充值记录，修改充值状态、余额、收银员等相关信息
		MAccountRechargeExample example = new MAccountRechargeExample();
		MAccountRechargeExample.Criteria criteria = example.createCriteria();
		criteria.andAccountIdEqualTo(finance.getAccountId());
		// 交易号（订单号）
		criteria.andOrderNoEqualTo(finance.getTradeNo());

		List<MAccountRecharge> rechargeList = (List<MAccountRecharge>) accountRechargeMapper.selectByExample(example);
		if (null == rechargeList || rechargeList.size() != 1) {
			result.setErrorCode(ResultDO.ACCOUNT_RECHARGE_ERROR);
			result.setErrorMsg("充值订单信息获取失败");
			result.setSuccess(false);
			logger.error("充值订单信息获取失败,数据为空或不唯一, id:" + finance.getAccountId() + ", tradeNo:" + finance.getTradeNo());
			return result;
		}

		MAccountRecharge mAccountRecharge = rechargeList.get(0);
		finance.setAccountId(mAccountRecharge.getAccountId());
		mAccountRecharge.setStatus(MemberConstant.STATUS_PAY); // 已支付
		mAccountRecharge.setPayDate(Calendar.getInstance().getTime()); // 完成支付时间
		mAccountRecharge.setModifitime(mAccountRecharge.getModifitime()); // 数据更新时间
		if (!isNumberInValid(finance.getCashierId())) {
			// 查询收银人员信息
			EmployeeDO employeeDO = getEmployeeById(finance.getCashierId());
			if (employeeDO == null) {
				result.setErrorCode(ResultDO.ACCOUNT_RECHARGE_ERROR);
				result.setErrorMsg("获取员工信息失败");
				result.setSuccess(false);
				return result;
			}
			// 设置收银人员姓名
			mAccountRecharge.setCashierID(finance.getCashierId());
			mAccountRecharge.setCashierName(employeeDO.getRealName());
			finance.setCashierName(employeeDO.getRealName());
			finance.setCreatetime(mAccountRecharge.getPayDate());
			finance.setAuthor(employeeDO.getRealName());
		}
		// 收银成功后，从账户信息表中重新读取最新余额，重新计算
		MAccount mAccount = accountMapper.selectByPrimaryKey(finance.getAccountId());
		mAccountRecharge.setModifi(finance.getAuthor()); // 数据更新
		mAccountRecharge.setBalance(
				mAccount.getBalance().add(mAccountRecharge.getRechargeAmount().add(mAccountRecharge.getGiftAmount())));
		int r = -1;
		try {
			// 更新充值订单表
			r = accountRechargeMapper.updateByPrimaryKeySelective(mAccountRecharge);
		} catch (Exception e) {
			e.printStackTrace();
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("充值记录更新失败");
			result.setSuccess(false);
			return result;
		}

		// 2. 更新账户信息表：余额、最近充值金额、最近充值时间等信息
		MAccount account = new MAccount();
		account.setId(finance.getAccountId());
		account.setBalance(
				mAccount.getBalance().add(mAccountRecharge.getRechargeAmount().add(mAccountRecharge.getGiftAmount())));
		account.setDeposit(mAccountRecharge.getRechargeAmount().add(mAccountRecharge.getGiftAmount()));
		account.setDepositDate(mAccountRecharge.getPayDate());
		account.setModifi(finance.getAuthor());
		account.setModifitime(Calendar.getInstance().getTime());
		try {
			r = accountMapper.updateByPrimaryKeySelective(account);
		} catch (Exception e) {
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("账户更新失败");
			result.setSuccess(false);
			logger.error("充值成功后，更新客户账户异常");
			return result;
		}
		if (r < 1) {
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("账户更新失败");
			result.setSuccess(false);
			logger.error("充值成功后，更新客户账户失败");
			return result;
		}

		// 3.新增资金记录表（充值金额等信息来源于充值记录表）
		finance.setRealName(mAccountRecharge.getCustomerName());
		finance.setTradeAmount(mAccountRecharge.getRechargeAmount());
		finance.setGiftAmount(mAccountRecharge.getGiftAmount());
		finance.setTotleAmount(mAccountRecharge.getRechargeAmount().add(mAccountRecharge.getGiftAmount()));
		finance.setBalance(mAccountRecharge.getBalance());
		finance.setIsDelete(MemberConstant.DB_ISDEL_NO);
		ResultDO res = addFinance(finance);
		if (!res.isSuccess()) {
			result.setErrorCode(res.getErrorCode());
			result.setErrorMsg("账户资金记录添加失败");
			result.setSuccess(false);
			logger.error("充值成功后，账户资金记录添加失败");
			return result;
		}

		// 新增时，更新solr数据
		//solrService.addRecord(account.getId());
		return result;
	}

	/** 通过客户id获取客户基本信息 */
	public ResultDO getAccountDetail(Integer id) {

		ResultSupport result = new ResultSupport();
		if (isNumberInValid(id)) {
			result.setErrorCode(ResultDO.QUERY_VALUE_SET_ERROR);
			result.setErrorMsg("参数错误");
			result.setSuccess(false);
			logger.error("账户id无效");
			return result;
		}

		try {
			// 获取账户信息
			ResultDO res1 = get(id);
			if (!res1.isSuccess()) {
				result.setErrorCode(ResultDO.CUSTOMER_GET_ERROR);
				result.setErrorMsg("账户信息获取失败");
				result.setSuccess(false);
				logger.error("客户账户信息获取失败, id:" + id);
				return result;
			}
			AccountDO accountDO = (AccountDO) res1.getModel(ResultSupport.FIRST_MODEL_KEY);
			if (accountDO == null) {
				result.setErrorCode(ResultDO.CUSTOMER_GET_ERROR);
				result.setErrorMsg("未查询到该账户信息");
				result.setSuccess(false);
				logger.error("未查询到该账户信息, id:" + id);
				return result;
			}

			// 获取客户主要联系人基础信息
			CustomerFamilyQueryDO query1 = new CustomerFamilyQueryDO();
			query1.setCustomerId(id);
			query1.setIsFirst(MemberConstant.FAMILY_IS_FIRST);
			res1 = customerFamilyService.query(query1);
			if (!res1.isSuccess()) {
				result.setErrorCode(ResultDO.CUSTOMER_GET_ERROR);
				result.setErrorMsg("客户联系人获取失败");
				result.setSuccess(false);
				logger.error("客户联系人获取失败");
				return result;
			}
			List<CustomerFamilyDO> list = (List<CustomerFamilyDO>) res1.getModel(ResultSupport.FIRST_MODEL_KEY);
			if (list == null || list.size() == 0) {
				result.setErrorCode(ResultDO.CUSTOMER_GET_ERROR);
				result.setErrorMsg("未查询到客户联系人信息");
				result.setSuccess(false);
				logger.error("未查询到客户联系人信息");
				return result;
			}

			accountDO.setFirstFamilyMember(list.get(0));
			result.setModel(ResultSupport.FIRST_MODEL_KEY, accountDO);
		} catch (Exception e) {
			e.printStackTrace();
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("获取客户信息失败");
			result.setSuccess(false);
			logger.error("获取客户信息失败");
			return result;
		}
		return result;
	}

	/** 新增账户资金记录 */
	private ResultDO addFinance(MAccountFinance accountFinance) {

		ResultSupport result = new ResultSupport();
		if (null == accountFinance) {
			result.setErrorCode(ResultDO.QUERY_VALUE_SET_ERROR);
			result.setErrorMsg("参数错误");
			result.setSuccess(false);
			logger.error("账户资金记录对象为空");
			return result;
		}
		// 查询客户信息
		int r = 0;
		try {
			r = accountFinanceMapper.insert(accountFinance);
		} catch (Exception e) {
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("账户资金记录添加失败");
			result.setSuccess(false);
			logger.error("账户资金记录添加异常");
			return result;
		}
		if (r < 1) {
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("账户资金记录添加失败");
			result.setSuccess(false);
			logger.error("账户资金记录添加失败");
			return result;
		}
		return result;
	}

	/** 查询门店信息 */
	private StoreDO getStroreById(Integer id) {
		com.jingyanzi.resallocation.result.ResultDO storeResultDO = getStoreService().get(id);
		if (!storeResultDO.isSuccess()) {
			return null;
		}
		return (StoreDO) storeResultDO.getModel(com.jingyanzi.resallocation.result.ResultSupport.FIRST_MODEL_KEY);
	}

	/** 余额充值或使用余额消费成功后，修改账户余额、增加资金记录、充值记录等 */
	@Override
	public ResultDO addFinanceRecord(AccountFinanceDO accountFinanceDO) {
		ResultSupport result = new ResultSupport();
		// 判断参数: 客户id, 充值订单交易号
		if (accountFinanceDO == null || isNumberInValid(accountFinanceDO.getAccountId())) {
			result.setErrorCode(ResultDO.QUERY_VALUE_SET_ERROR);
			result.setErrorMsg("参数错误");
			result.setSuccess(false);
			logger.error("消费记录DO对象为空");
			return result;
		}

		MAccountFinance finance = new MAccountFinance();
		result = BeanUtilsExtends.copy(finance, accountFinanceDO);
		if (!result.isSuccess()) {
			result.setSuccess(false);
			result.setErrorCode(ResultDO.PROPERTY_VALUE_SET_ERROR);
			result.setErrorMsg("资金记录信息转换失败");
			logger.error("账户资金记录对象转换失败");
			return result;
		}
		// 交易类型为充值交易时
		// 1.账户充值时，调用充值订单更新接口
		if (finance.getTradeType() == MemberConstant.TRADE_TYPE_RECHARGE) {
			return updateRecharge(accountFinanceDO);
		}
		// 2.使用余额消费时:根据收银台返回的信息，修改相关数据表：账户表；资金记录表
		// (1)更新账户信息表：余额、最近消费金额、最近消费时间等信息
		ResultDO res = getAccountDetail(finance.getAccountId());
		if (!res.isSuccess()) {
			return res;
		}
		AccountDO accountDO = (AccountDO) res.getModel(ResultSupport.FIRST_MODEL_KEY);
		// 判断余额是否足够支付
		if (accountDO.getBalance().compareTo(finance.getTotleAmount()) < 0) {
			result.setErrorCode(ResultDO.BALANCE_LACK_ERROR);
			result.setErrorMsg(ResultDO.BALANCE_LACK_ERROR_MSG);
			result.setSuccess(false);
			logger.error("账户余额不足，账户余额:" + accountDO.getBalance() + ", 待支付:" + finance.getTotleAmount());
			return result;
		}
		MAccount mAccount = new MAccount();
		mAccount.setId(accountDO.getId());
		mAccount.setBalance(accountDO.getBalance().subtract(finance.getTotleAmount()));
		mAccount.setPayment(finance.getTotleAmount());
		mAccount.setPayDate(Calendar.getInstance().getTime());
		mAccount.setModifitime(mAccount.getPayDate());
		mAccount.setModifi(finance.getAuthor());
		// (2)查询收银人员信息
		if (!isNumberInValid(finance.getCashierId())) {
			EmployeeDO employeeDO = getEmployeeById(finance.getCashierId());
			if (employeeDO == null) {
				result.setErrorCode(ResultDO.ACCOUNT_RECHARGE_ERROR);
				result.setErrorMsg("获取员工信息失败");
				result.setSuccess(false);
				logger.error("获取员工信息失败, 员工id:" + finance.getCashierId());
				return result;
			}
			finance.setCashierName(employeeDO.getRealName());
		}
		// (3)更新账户信息表
		int r = -1;
		try {
			r = accountMapper.updateByPrimaryKeySelective(mAccount);
			logger.info("账户本次消费:" + finance.getTotleAmount() + "，最新余额:" + mAccount.getBalance());
		} catch (Exception e) {
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("账户信息更新失败");
			result.setSuccess(false);
			logger.error("客户账户信息更新异常");
			return result;
		}
		if (r < 1) {
			result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("账户信息更新失败");
			result.setSuccess(false);
			logger.error("客户账户信息更新失败");
			return result;
		}
		// (4)新增资金记录表
		finance.setRealName(accountDO.getFirstFamilyMember().getName());
		finance.setBalance(mAccount.getBalance());
		finance.setCreatetime(mAccount.getPayDate());
		finance.setIsDelete(MemberConstant.DB_ISDEL_NO);
		addFinance(finance);

		// 新增时，更新solr数据
		//solrService.addRecord(accountDO.getId());
		return result;
	}

	/**
	 * 对象拷贝单个实体到对象中
	 * 
	 * @param obj
	 * @return 返回DO对象
	 */
	public AccountPayDO getAccountPayDO(MAccountPay obj) {
		if (obj == null)
			return null;
		AccountPayDO dst = new AccountPayDO();
		return BeanUtilsExtends.copyProperties(dst, obj) ? dst : null;
	}

	/**
	 * 对象拷贝多个实体到列表中
	 * 
	 * @param List
	 * @return List
	 */
	public List<AccountPayDO> getAccountPayDOList(List<MAccountPay> list) {
		List<AccountPayDO> result = new ArrayList<AccountPayDO>();
		if (list != null && !list.isEmpty()) {
			for (MAccountPay org : list) {
				AccountPayDO org1 = getAccountPayDO(org);
				if (org1 != null) {
					org1.setCreateTimeName(String.valueOf(org.getCreatetime().getTime()));
					// 设置交易类型、支付方式等
					org1.setTradeTypeName(StaticDicUtil.PAY_CASH_NAMES.get(org.getTradeType()));
					org1.setPayModeName(StaticDicUtil.PAY_METHOD_NAMES.get(org.getPayMode()));
					if (null != org.getTradingDate()) {
						org1.setTradingStamp(String.valueOf(org.getTradingDate().getTime()));
					}
					result.add(org1);
				}
			}
		}
		return result;
	}
	
	public AccountDO getAccountDO(MAccount obj) {
		if (obj == null)
			return null;
		AccountDO dst = new AccountDO();
		if(BeanUtilsExtends.copyProperties(dst, obj)) {
			if (dst != null) {
				dst.setCreateTimeName(String.valueOf(obj.getCreatetime().getTime()));
				if (obj.getDepositDate() != null) {
					dst.setDepositStamp(String.valueOf(obj.getDepositDate().getTime()));
				}
				if (obj.getPayDate() != null) {
					dst.setPayDateStamp(String.valueOf(obj.getPayDate().getTime()));
				}
				return dst;
			}
		}
		return null;
	}

	/**
	 * 对象拷贝多个实体到列表中
	 * 
	 * @param List
	 * @return List
	 */
	public List<AccountDO> getAccountDOList(List<MAccount> list) {
		List<AccountDO> result = new ArrayList<AccountDO>();
		if (list != null && !list.isEmpty()) {
			for (MAccount org : list) {
				result.add(getAccountDO(org));
			}
		}
		return result;
	}
}